package com.demo.spring.security.config;

import liquibase.integration.spring.SpringLiquibase;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

import javax.sql.DataSource;

/**
 * liquibase配置
 */
@Configuration
@EnableConfigurationProperties({LiquibaseProperties.class})
@RequiredArgsConstructor(onConstructor=@__({@Autowired,@Lazy}))
public class CusLiquibaseConfig {

    private final LiquibaseProperties properties;

    @Bean
    public SpringLiquibase liquibase(DataSource dataSource){
        SpringLiquibase liquibase = new SpringLiquibase();
        liquibase.setDataSource(dataSource);
        liquibase.setContexts("development,test,production");
        liquibase.setChangeLog("classpath:database/master.xml");
        liquibase.setShouldRun(properties.isEnabled());
        return liquibase;
    }
}
